from bs4 import BeautifulSoup
import requests

special = {
    '顾金晨': '2018302397',
    '黄凯勋': '2018303214',
    '刘成文': '2018302295',
    '王烁宇': '2018303330',
    '王煜伟': '2018302275',
    '张浩': '2018302409',
}

s = {special[x] for x in special}

special_list = [special[x] for x in special]

def get_user_list():
    with open('rank.html', "r", encoding="utf-8") as f:
        html = f.read()
    bs = BeautifulSoup(html, 'lxml')
    all_user = get_all_user()
    res = []
    not_rank_res = []
    not_real_name = []
    for x in bs.find_all("div"):
        try:
            name = x.a.span.get_text()[1:-1]
            if name in all_user:
                if name not in special:
                    res.append(all_user[name])
                else:
                    not_rank_res.append(all_user[name])
            else :
                not_real_name.append(name)
        except :
            not_real_name.append(x.a.get_text())
    print("--- Not Real Name ---:\n ", not_real_name, '\n')
    return res, not_rank_res

def get_all_user():
    url = "http://49.235.56.17:8000/scorelist/manage"
    html = requests.get(url).text
    res = {}
    bs = BeautifulSoup(html, 'lxml')
    tags = bs.find('table').find_all('tr')
    for i in range(1, len(tags)):
        info = tags[i].find_all('td')
        sid, name = info[0].get_text(), info[1].get_text()
        res[name] = sid
    return res

